﻿<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Demo</title>
    <script src="./js/aliyun-sdk.min.js"></script>

  <script src="./js/oss-js-upload.js"></script>
  
  <script src="./js/jquery-1.8.3.min.js"></script>
</head>
<body>




<script>
//定义几个全局变量 
var AppUrl = "http://127.0.0.1:8888";//整个页面的请求页面
var pageSize = 2;
var currentPage = 0;

$(function(){

	$.ajax( {  
      url:AppUrl+'/backStage/Admmin_Goods/showAllGoods',// 跳转到 action  addUser
      data:{
		"pageSize":pageSize,
		'currentPage':currentPage
	  },  
     type:'post',  
     cache:false,  
     dataType:'json',  
     success:function(data) {  
		showData(data);
      },  
      error : function() {  
           alert("异常！");  
      }  
	});

});


function showData(data){
	var str = '';
		str += "<table style='width:100%;'>";
		for(var i=0;i<data.length;i++){
			str += "<tr style='border:2px solid #31ACF8;'>"
			str += "<td style='border:2px solid #31ACF8;line-height:-50px;'>"+data[i].goods_name+"</td>";
			str += "<td style='border:2px solid #31ACF8;'><span style='color:red;margin-left:20px;'>"+data[i].goods_price+"</span></td>";
			str += "<td style='border:2px solid #31ACF8;'><span style='margin-left:20px;'>"+data[i].goods_desc+"</span></td>";
			str += "<td style='border:2px solid #31ACF8;'><img style='margin-left:20px;width:100px;height:100px;' src='http://biluo.oss-cn-qingdao.aliyuncs.com/"+data[i].file_name+"'/></td>";
			str += "<td style='border:2px solid #31ACF8;'><a style='margin-left:20px;' href='#' onclick=\"delGoodById('"+data[i]._id+"')\">删除</a></td>";
			str += "<td style='border:2px solid #31ACF8;'><a style='margin-left:20px;'  href=\"updateGoodById.html?id="+data[i]._id+"\" >修改</a></td>";
			str += "</tr>";	
		}
		str += "</table>";
		document.getElementById("showGoods").innerHTML = str;
}


function  next(){
	currentPage = parseInt(currentPage)+parseInt(pageSize);
	$.ajax( {  
      url:AppUrl+'/backStage/Admmin_Goods/showAllGoods',// 跳转到 action  addUser
      data:{
		"pageSize":pageSize,
		'currentPage':currentPage
	  },  
     type:'post',  
     cache:false,  
     dataType:'json',  
     success:function(data) {  
		showData(data);
      },  
      error : function() {  
           // view("异常！");  
           alert("异常！");  
      }  
	});
}

function  pre(){
	currentPage = parseInt(currentPage)-parseInt(pageSize);
	$.ajax( {  
      url:AppUrl+'/backStage/Admmin_Goods/showAllGoods',// 跳转到 action  addUser
      data:{
		"pageSize":pageSize,
		'currentPage':currentPage
	  },  
     type:'post',  
     cache:false,  
     dataType:'json',  
     success:function(data) {  
		showData(data);
      },  
      error : function() {  
           alert("异常！");  
      }  
	});
}


function delGoodById(id){
	$.ajax( {  
      url:AppUrl+'/backStage/Admmin_Goods/delGoodById',// 跳转到 action  addUser
      data:{
		"id":id
	  },  
     type:'post',  
     cache:false,  
     dataType:'json',  
     success:function(data) {  
        alert("返回数据--"+data);
		if(data == 2){
			alert("删除成功");
		}
      },  
      error : function() {  
           alert("异常！");  
      }  
	});
}



</script>

<div id="showGoods" style="width:100%;">


</div>


<a href="#" onclick="pre()">上一页</a>  <a href="#" onclick="next()">下一页</a>

</body>
</html>
